
<?php
$this->breadcrumbs = array(
    'Ticket Management',
);
?>  

<div>
    <div class="pull-right">
        <div class="widget-toolbar">				
            <a href="<?php echo Yii::app()->createUrl('bookingsystem/ticket/precreate'); ?>" role="button" class="white" data-toggle="modal"  title="Add new ticket">
                <i class="icon-plus"></i>
            </a>
        </div>
    </div>
</div>
<div class="row-fluid">

    <div class="row-fluid">

        <div class="table-header">
            Ticket Management       
        </div> 
        <div class="row-fluid">
            <div class="today">
                <form action="<?php echo Yii::app()->createUrl('bookingsystem/ticket') ?>" method="POST" id="date_time" style="margin:0;">
                    <div class="row-fluid input-append">
                        <input type="text" value="<?php if (isset($start_date)) {
    echo $start_date;
} else {
    echo date('d-m-Y');
} ?>" id="Event_date" name="Event[date]" class="date-picker" readonly="readonly" data-date-format="dd-mm-yyyy">                                       <span class="add-on">
                            <i class="icon-calendar"></i>
                        </span>
                        <span class="help-inline"><div style="display:none" id="Event_expired_date_em_" class="errorMessage"></div></span>
                    </div>                    
                </form>
            </div>
        </div>    
        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>Event Code</th>
                    <th>Main Title</th>
                    <th>Ticket Code</th>
                    <!--<th>Event</th>-->
                    <th>Des</th>
                    <th>Price</th>
                    <th>Quan</th>
                    <th>R-Q</th>
                    <th>Created date</th>
                    <th>Last Update</th>
                    <!-- <th>Created By</th> -->
                    <!--Danh cho icon-->
<!--                     <th></th> -->
                    <!--Danh cho icon--> 
                </tr>
            </thead>
            <tbody>
<?php if (count($model) > 0) : ?>
    <?php foreach ($model as $items) : ?>
        <?php if ($items->tickets != null) : ?>
                            <tr>
                                <td>
                                    <b class="green"><?php echo $items->event_code; ?></b>
                                </td>
                                <td class="span2">
                                        <?php echo $items->translate[1]['main_title']; ?>
                                </td>
                                <td>
                                    <ul class="items-table">                           
            <?php foreach ($items->tickets as $tickets) : ?>
                                            <li >
                                                <div class="pull-left">
                                                    <a class="blue views-details-ticket" href="#modal-form" role="button" data-toggle="modal" rel="<?php echo $tickets->id; ?>">
                                                        <b>
                                                            <?php echo $tickets->ticket_code; ?>
                                                        </b>
                                                    </a>
                
                                                </div>
                                                <div class="pull-right">
                                                    
                                                    <a class="green" href="<?php echo Yii::app()->createAbsoluteUrl('bookingsystem/ticket/update', array('id' => $tickets->id, 'event_id' => $items->id)); ?>">
                                                        <i class="icon-pencil bigger-130"></i>
                                                    </a>
                                                </div>

                                            </li>                             
            <?php endforeach; ?>
                                    </ul>
                                </td>
                                <td>
                                    <ul class="items-table">                           
                                                <?php foreach ($items->tickets as $tickets) : ?>
                                            <li>
                                                <b class="green">
                <?php echo $tickets->description_of_ticket; ?>
                                                </b>

                                            </li>                               
            <?php endforeach; ?>
                                    </ul>
                                </td>
                                <td>
                                    <ul class="items-table">                           
            <?php foreach ($items->tickets as $tickets) : ?>
                                            <li>
                                                <b class="red"><?php echo number_format($tickets->price); ?> VND</b>
                                            </li>                               
            <?php endforeach; ?>
                                    </ul>
                                </td>
                                <td>
                                    <ul class="items-table">                           
            <?php foreach ($items->tickets as $tickets) : ?>
                                            <li>
                                                <b class="blue"><?php echo MyFunctionCustom::remain_quantity($tickets->quantity,$tickets->temp_quantity,null); ?></b>
                                            
                                            </li>                               
            <?php endforeach; ?>
                                    </ul>
                                </td>
                                <td>
                                    <ul class="items-table">                           
                                            <?php foreach ($items->tickets as $tickets) : ?>
                                            <li>
                                                <?php $real_quantity = MyFunctionCustom::remain_quantity(null,$tickets->temp_quantity,$tickets->remain_quantity); ?>
                                                <?php if ($real_quantity < 10) : ?>
                                                    <b class="red">
                                                        <?php echo $real_quantity;  ?>
                                                    </b>
                                                <?php else : ?>
                                                    <b class="blue"><?php echo $real_quantity; ?></b>
                                                <?php endif; ?>
                                            </li>                               
            <?php endforeach; ?>
                                    </ul>
                                </td>
                                <td>
                                    <ul class="items-table">                           
                                            <?php foreach ($items->tickets as $tickets) : ?>
                                            <li>
                                            <?php echo date("H:i / d-M-Y", strtotime($tickets->date)); ?>
                                            </li>                               
            <?php endforeach; ?>
                                    </ul>
                                </td>
                                <td>
                                    <ul class="items-table">                           
                                            <?php foreach ($items->tickets as $tickets) : ?>
                                            <li>
                                                <?php if($tickets->updated_date != null) : ?>
                                                    <?php echo date("H:i / d-M-Y", strtotime($tickets->updated_date)); ?>
                                                <?php else : ?>
                                                    Not Available
                                                <?php endif; ?>
                                            </li>                               
            <?php endforeach; ?>
                                    </ul>
                                </td>

                            </tr>
                        <?php endif; ?>
    <?php endforeach; ?>
<?php endif; ?>

            </tbody>
        </table>
    </div>
</div><!--/.row-fluid-->
<div id="modal-form" class="modal hide" tabindex="-1">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="blue bigger"></h4>
    </div>

    <div class="modal-body overflow-visible">

    </div>
    <div class="modal-footer">
        <button class="btn btn-small" data-dismiss="modal">
            <i class="icon-remove"></i>
            Close
        </button>
    </div>
</div>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $('.action-buttons').each(function(){
            $(this).find('a').eq(2).append('<i class="icon-trash bigger-130"></i>');
        });
     
    });
    
    $('#Event_date').change(function(){
        $(this).parent().parent('form').submit();
    });    
    $('.views-details-ticket').on('click',function(){
        var title = "Views Ticket Details";
        var ticket_id = $(this).attr('rel');
        $.ajax({
            url: '<?php echo Yii::app()->createAbsoluteUrl("bookingsystem/ticket/view") ?>',
            data: {ticket_id:ticket_id},
            async: true,
            beforeSend: function(){
                $('.modal-header h4').empty();
                $('.modal-header h4').append(title);
                $('.modal-body').empty();
                $('.modal-body').append('<div class="loading"><div style="width:134px;height:100px;margin:0 auto;padding-top: 10px;"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/images/ajaxloader.gif"></div></div>');
            },
            success: function(data){

                $('.modal-body').html(data);
            }
        });
    });
</script>

<style>

    .today {
        position: absolute;
        right: 55px;
        top: 54px;
    }

    .today input{
        width: 100px;
    }

    .icon-calendar{
        /*background-color: black;*/
    }

    .add-on i{
        color: black;
    }
</style>
